package com.ptswitch.material.mixins;

import java.util.HashMap;
import java.util.Map;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeforeRenderBody;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.AssetSource;

public class Icon {

    @Parameter(defaultPrefix = BindingConstants.LITERAL)
    private String icon;
    //
    @Inject
    private AssetSource assetSource;

    @BeforeRenderBody
    void render(MarkupWriter writer) {
        String imgSrc = getIcon(icon);
        writer.element("img", "src", assetSource.getContextAsset(imgSrc, null));
        writer.end();
    }

    //----------------------------
    private static final Map<String, String> iconMap = new HashMap<String, String>();

    private static void addIcon(String icon, String path) {
        iconMap.put(icon, path);
    }

    private static String getIcon(String icon) {
        return iconMap.get(icon);
    }

    static {
        addIcon("sendmail", "css/images/easyicon-mail-send-12953.png");
        addIcon("list", "css/images/EasyiconList.png");
        addIcon("view", "css/images/easyicon-view-37736.png");
        addIcon("delete", "css/images/EasyiconDelete.png");
        addIcon("deleteAll", "css/images/EasyiconDeleteAll.png");
        //
        addIcon("deleteUser", "css/images/EasyiconDeleteUser.png");
        addIcon("addUser", "css/images/EasyiconAddUser.png");
        addIcon("listUser", "css/images/EasyiconListUser.png");
        //
        addIcon("deleteRole", "css/images/EasyiconDeleteUser.png");
        addIcon("addRole", "css/images/EasyiconAddUser.png");
        addIcon("listRole", "css/images/EasyiconListUser.png");
        //
        addIcon("logout", "css/images/EasyiconLogout.png");
        addIcon("check", "css/images/EasyiconChecked.png");
        addIcon("upload", "css/images/EasyiconUpload.png");
        addIcon("download", "css/images/EasyiconDownload3.png");
        addIcon("add", "css/images/EasyiconAdd.png");
        addIcon("search", "css/images/EasyiconSearch.png");
        addIcon("forward", "css/images/KnobForward.png");
        addIcon("back", "css/images/KnobLeft.png");
        addIcon("modify", "css/images/KnobAttention.png");
        addIcon("edit", "css/images/EasyiconEdit.png");
        addIcon("cancel", "css/images/easyicon-cancel-5245.png");
        addIcon("ok", "css/images/KnobValidGreen.png");
        addIcon("message", "css/images/KnobMessage.png");
        addIcon("reset", "css/images/KnobAttention.png");
        addIcon("relate", "css/images/KnobForward.png");
        addIcon("enter", "css/images/KnobForward.png");
    }
}
